<template>
	<view>
		<view>http请求</view>
		<view v-if="arr.length>0">{{arr.length}}</view>
		<button @click="get">get请求测试</button>
		<button @click="post">post请求测试</button>
		<button @click="testmysql">测试数据库链接</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				arr:[]
			}
		},
		methods: {
			testmysql(){
				uni.request({
					url:'http://localhost/test/mysql',
					success(res){
						console.log(res)
					}
				})
			},
			post(){
				uni.request({
					url:'http://localhost/test/post',
					method:"post",
					data:{
						a:3,
						b:4
					},
					success:function(res){
						console.log(res.data)
					}
				})
			},
			get(){
				uni.request({
					url:'http://localhost/test/get?a=1&b=2',
					method:'get',//get请求是默认的不写也行
					success:function(res){
						console.log(res.data)
					}
				})
			}
		},
		onShow(){
			this.arr=[1,2,3]
		}
	}
</script>

<style>

</style>
